<?php
/**
 *
 *
 */
namespace Yz\modules\Generic;

use Yz_Array,
    Yz_Hash;

class Controller_Add
    extends Controller_Edit
{

    const ERROR_UNIQUE = ':Unique';

    /** The list of required arguments for controller: no default arguments for Add
     *  @var array
     */
    protected $arguments = array();

    /** allow presence in automatic menus
     *  @const ???
     */
    const IN_MENU = true;

    /**
     *  URL to redirect to after successful add
     *  Set to false to disable redirect
     *  @var string|false
     */
    protected $redirectURL;


    /****************************
     *      Public methods      *
     ****************************/



    /******************************
     *     Protected methods      *
     ******************************/


    /**
     *  @return item
     */
    protected function fetchItem()
    {
        debug();
        return $this->selectModel()->newItem();
    }



    /**
     *
     */
    protected function output()
    {
        if ($this->success) {
            $url = $this->getRedirectURL();
            if ($url) {
                $this->getView()->setRedirect( $url ) ;
                return $this;
            }
        }
        return parent::output();
    }

    /**
     *
     */
    protected function getRedirectURL()
    {
        $url = $this->redirectURL;
        if (null !== $url)
            return $url;
        $url = $this->module->getWebPath() . '/edit' ;
        return $url . '/' . $this->item->id;
    }

}
